//
//  SLAlgorithmController.m
//  Objective-C
//
//  Created by S_Line on 2018/9/4.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLAlgorithmController.h"

#import "SLAlgorithmViewModel.h"

@interface SLAlgorithmController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) SLAlgorithmViewModel *viewModel;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topContraints;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraints;

@end

@implementation SLAlgorithmController

- (void)initNavBar {
    self.navTitle = @"算法";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavBar];
    
    [self initData];
    
    [self initView];
}

- (void)initData {
    self.viewModel = [[SLAlgorithmViewModel alloc] init];
}

- (void)initView {
    
    self.topContraints.constant = kNavigationBarHeight;
    self.bottomConstraints.constant = kSafeBottomMargin;
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

#pragma mark ----- UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [_viewModel numberOfSections];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_viewModel numberOfRowsInSection:section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SLAlgorithmModelItem *item = [_viewModel dataForRowAtIndexPath:indexPath];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"algorithmCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"algorithmCell"];
    }
    
    cell.textLabel.text = item.name;
    
    return cell;
}

@end
